package com.jinyang.jetpackdemo.util.http

import com.jinyang.jetpackdemo.BuildConfig
import com.jinyang.jetpackdemo.util.SPUtils


/**
 * @Author: LiuJinYang
 * @CreateDate: 2020/5/16 9:32
 *
 *
 * baseUrl
 */
object BaseUrl {
    /**
     * 开发
     */
    const val HTTP_TYPE_DEBUG = 3

    /**
     * 测试
     */
    const val HTTP_TYPE_BETA = 2

    /**
     * 预生产
     */
    const val HTTP_TYPE_PRE = 1

    /**
     * 生产
     */
    const val HTTP_TYPE_RELEASE = 0

    /**
     * 开发/联调 环境的baseUrl
     */
    private const val BASE_URL_DEBUG = "https://overseas-ins-app.dev.gwim.com.hk/"
    /**
     * 测试环境的baseUrl
     */
    private const val BASE_URL_BETA = "https://overseas-ins-app.qasa.gwim.com.hk/"
    /**
     * 预生产环境的baseUrl
     */
    private const val BASE_URL_PRE = "https://overseas-ins-app-uata.runpozx.com/"
    /**
     * 生产环境（线上）的baseUrl
     */
    private const val BASE_URL_RELEASE = "https://overseas-ins-app.runpozx.com/"
    /**
     * app更新域名-开发环境
     */
    private const val BASE_URL_DEBUG_UPDATE = "https://app-api.qasa.runpozx.com/"

    /**
     * app更新域名-测试环境
     */
    private const val BASE_URL_BATE_UPDATE = "https://app-api.qasa.runpozx.com/"

    /**
     * app更新域名-预生产环境
     */
    private const val BASE_URL_PRE_UPDATE = "https://app-api.uata.runpozx.com/"

    /**
     * app更新域名-生产环境
     */
    private const val BASE_URL_RELEASE_UPDATE = "https://app-api.runpozx.com/"
    const val CHANGE_BASE_URL = "changeBaseUrl"

    /**
     * 获取 baseUrl
     */
    @JvmStatic
    val baseUrl: String
        get() {
            var httpType = BuildConfig.HTTP_TYPE
            if (BuildConfig.IS_DEBUG) {
                val type =SPUtils.getInstance()
                    .getInt(CHANGE_BASE_URL, -1)
                if (type != -1) {
                    httpType = type
                }
            }
            return when (httpType) {
                HTTP_TYPE_DEBUG -> BASE_URL_DEBUG
                HTTP_TYPE_BETA -> BASE_URL_BETA
                HTTP_TYPE_PRE -> BASE_URL_PRE
                HTTP_TYPE_RELEASE -> BASE_URL_RELEASE
                else -> BASE_URL_RELEASE
            }
        }

    /**
     * 获取 baseUrl
     */
    @JvmStatic
    val h5BaseUrl: String
        get() {
            var httpType = BuildConfig.HTTP_TYPE
            if (BuildConfig.IS_DEBUG) {
                val type = SPUtils.getInstance()
                    .getInt(CHANGE_BASE_URL, -1)
                if (type != -1) {
                    httpType = type
                }
            }
            return when (httpType) {
                HTTP_TYPE_DEBUG -> BASE_URL_DEBUG
                HTTP_TYPE_BETA -> BASE_URL_BETA
                HTTP_TYPE_PRE -> BASE_URL_PRE
                HTTP_TYPE_RELEASE -> BASE_URL_RELEASE
                else -> BASE_URL_RELEASE
            }
        }

    /**
     * 获取app更新 baseUrl
     */
    @JvmStatic
    val appUpdateBaseUrl: String
        get() {
            var httpType = BuildConfig.HTTP_TYPE
            if (BuildConfig.IS_DEBUG) {
                val type = SPUtils.getInstance()
                    .getInt(CHANGE_BASE_URL, -1)
                if (type != -1) {
                    httpType = type
                }
            }
            return when (httpType) {
                HTTP_TYPE_DEBUG -> BASE_URL_DEBUG_UPDATE
                HTTP_TYPE_BETA -> BASE_URL_BATE_UPDATE
                HTTP_TYPE_PRE -> BASE_URL_PRE_UPDATE
                HTTP_TYPE_RELEASE -> BASE_URL_RELEASE_UPDATE
                else -> BASE_URL_RELEASE_UPDATE
            }
        }
}